package com.vending.controller;

import com.vending.common.response.Result;
import com.vending.model.entity.Point;
import com.vending.service.PointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "点位管理")
@RestController
@RequestMapping("/api/points")
public class PointController {
    
    @Autowired
    private PointService pointService;

    @ApiOperation("获取点位列表")
    @GetMapping
    public Result<List<Point>> list(Point point) {
        return Result.success(pointService.list(point));
    }

    @ApiOperation("获取点位详情")
    @GetMapping("/{id}")
    public Result<Point> getById(@PathVariable Integer id) {
        return Result.success(pointService.getById(id));
    }

    @ApiOperation("添加点位")
    @PostMapping
    public Result<Void> add(@RequestBody Point point) {
        pointService.add(point);
        return Result.success(null);
    }

    @ApiOperation("更新点位")
    @PutMapping("/{id}")
    public Result<Void> update(@PathVariable Integer id, @RequestBody Point point) {
        point.setId(id);
        pointService.update(point);
        return Result.success(null);
    }

    @ApiOperation("删除点位")
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Integer id) {
        pointService.delete(id);
        return Result.success(null);
    }
} 